package com.hdax.dm.Controller;

import com.hdax.dm.dto.IndexNavDto;
import com.hdax.dm.service.ItemTypeService;
import com.hdax.dm.exceptions.DmException;
import com.hdax.dm.utils.response.CommonResponse;
import com.hdax.dm.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/item")
public class IndexNavController {

    @Autowired
    private ItemTypeService itemTypeService;
    /**
     * 首页导航数据查询显示（一级导航，二级导航，热门商品（5））
     * @return
     */
    @PostMapping("index/nav")
    public CommonResponse<List<IndexNavDto>> indexnav(){
        return itemTypeService.navs();
    }

    /* 局部 凡是本类中的方法抛出相关异常，都会进入该方法进行统一处理*/
    @ExceptionHandler(value = {DmException.class})
    public CommonResponse<String> exceptionHandler(DmException e){
        return ResponseUtil.returnFail(e);
    }
}
